package com.guoyihao.codesandbox.controller;

import com.guoyihao.codesandbox.codesandbox.CodeSandBox;
import com.guoyihao.codesandbox.codesandbox.CodeSandBoxFactory;
import com.guoyihao.codesandbox.model.ExecuteCodeRequest;
import com.guoyihao.codesandbox.model.ExecuteCodeResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
public class MainController {
    @Autowired
    private CodeSandBoxFactory codeSandBoxFactory;

    @GetMapping("/health")
    public String healthCheck() {
        return "ok";
    }

    @PostMapping("/executeCode")
    public ExecuteCodeResponse executeCode(@RequestBody ExecuteCodeRequest executeCodeRequest){
        return codeSandBoxFactory.getCodeSandBox(executeCodeRequest.getLanguage()).executeCode(executeCodeRequest);
    }

}
